﻿using Coolzon.UI.Common.RealtimeProxies;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Coolzon.UI.ViewerApp
{
    public class Config
    {
        public static Config Current { get; set; }
        public static AppSettings AppSettings { get; set; }

        public Endpoint[] RealtimeEndpoints { get; set; }
        /// <summary>
        /// 默认的解决方案，如果这个有，那么直接进入改方案
        /// </summary>
        public string DefaultSolution { get; set; }

        /// <summary>
        /// 获取配置文件的url地址
        /// </summary>
        /// <param name="baseUrl"></param>
        /// <returns></returns>
        public static string GetConfigUrl()
        {
            return string.Format("{0}Api/ConfigFile/ViewerApp", AppSettings.WebAppBaseUrl);
        }

        /// <summary>
        /// 获取日志存放目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}Logs\\", AppSettings.StorageDirectory);
        }

        /// <summary>
        /// 获取存放所有组件库的目录
        /// </summary>
        /// <returns></returns>
        public static string GetLibrariesDirectory()
        {
            return string.Format("{0}Libraries\\", AppSettings.StorageDirectory);
        }

        /// <summary>
        /// 获取存放所有方案的目录
        /// </summary>
        /// <returns></returns>
        public static string GetSolutionsDirectory()
        {
            return string.Format("{0}Solutions\\", AppSettings.StorageDirectory);
        }

        /// <summary>
        /// 获取缓存数据文件存放的路径
        /// </summary>
        /// <returns></returns>
        public static string GetCahceDataDirectory()
        {
            return null;
        }

        internal static string GetSolutionFile(string solution)
        {
            return string.Format("{0}Solutions\\{1}\\{1}.xml", AppSettings.StorageDirectory, solution);
        }

        internal static string GetSolutionDirectory(string solution)
        {
            return string.Format("{0}Solutions\\{1}\\", AppSettings.StorageDirectory, solution);
        }

        internal static string GetSolutionFileDownloadUrl(string solution, string fileRelatiePath)
        {
            return string.Format("{0}api/Solution/download?solution={1}&relativePath={2}", AppSettings.WebAppBaseUrl, solution,
            Uri.EscapeUriString(fileRelatiePath));
        }

        /// <summary>
        /// 获取library文件的下载地址
        /// </summary>
        /// <param name="name"></param>
        /// <param name="version"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        internal static string GetLibraryFileDownloadUrl(string name, string version, string file)
        {
            return string.Format("{0}api/Library/download?name={1}&version={2}&file={3}", AppSettings.WebAppBaseUrl, name,
            Uri.EscapeUriString(version),
            Uri.EscapeUriString(file));
        }
    }
    public class AppSettings
    {
        /// <summary>
        /// c:\\coolzon\\2.0\\ViewerApp\\
        /// </summary>
        public string StorageDirectory { get; set; }
        public string WebAppBaseUrl { get; set; }
    }
}
